package com.sun.mybatisplus.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auth: syh
 * @Date: 2021/10/18 16:06
 * @Email: 1014170249@qq.com
 * @Desc: 不在能知，而在能行
 * ES的配置信息
 */
@Configuration
public class ElasticSearchConfig {

    @Value("${elsaticsearch.host}")
    private String host;
    @Value("${elsaticsearch.port}")
    private String port;

    /**
     * 单机版的配置
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host, Integer.parseInt(port), "http")));
    }
}
